package cn.tedu.blackhorse.controller;

import cn.tedu.blackhorse.pojo.dto.PermissionAddNewDTO;
import cn.tedu.blackhorse.pojo.dto.PermissionUpdateDTO;
import cn.tedu.blackhorse.pojo.vo.PermissionListItemVO;
import cn.tedu.blackhorse.pojo.vo.TeacherListItemVO;
import cn.tedu.blackhorse.service.IPermissionService;
import cn.tedu.blackhorse.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/permission")
@Api(tags = "权限表")
@Validated
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    public PermissionController() {
        log.info("创建控制器：PermissionController");
    }

    @ApiOperation("/增加新权限")
    @ApiOperationSupport(order = 100)
    @PostMapping("/addNew")
    @ApiImplicitParam(name = "id", value = "权限id", required = true, dataType = "long")
    public JsonResult<Void> addNew(PermissionAddNewDTO permissionAddNewDTO) {
        log.debug("开始处理【增加权限信息】的请求");
        permissionService.addNew(permissionAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("权限信息列表")
    @ApiOperationSupport(order = 200)
    @GetMapping("")
    public JsonResult<List<PermissionListItemVO>> list() {
        log.debug("开始处理【老师信息列表】的请求");
        List<PermissionListItemVO> list = permissionService.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("修改权限信息")
    @ApiOperationSupport(order = 300)
    @GetMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id, PermissionUpdateDTO permissionUpdateDTO) {
        log.debug("开始处理【修改权限信息】的请求");
        permissionService.updateById(id, permissionUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除权限")
    @ApiOperationSupport(order = 300)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除权限】的请求：id={}", id);
        permissionService.deleteById(id);
        return JsonResult.ok();
    }

}
